{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}R:\WSV2\TBu_AKe\Spatial_NEW\spatial_4_spgen.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}28 Mar 2023, 17:32:56
{txt}
{com}. 
.         **************************
.         ** V-Shaped (sectors S) **
.         **************************
.         
. cd "R:\WSV2\TBu_AKe\Spatial_NEW\Wmat_Fan"
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Wmat_Fan
{txt}
{com}.                         
. /*                      
> ***************************
> *** Sectors 1-4 ***********
> *** smaller j *************
> ***************************
> 
> use spatial_3_wmat_fan_1234 
> 
> xtset cell 
> spset cell // must by spset. 
> 
>                 *** S1
> spmatrix fromdata S1 = s1_1 - s1_4950, normalize(none) 
> 
> spmatrix save S1 using S1.stswm, replace // inverse: spmatrix use 
> 
>                 *** S2
> spmatrix fromdata S2 = s2_1 - s2_4950, normalize(none) 
> 
> spmatrix save S2 using S2.stswm, replace // inverse: spmatrix use 
> 
>  
>                 *** S3
> spmatrix fromdata S3 = s3_1 - s3_4950, normalize(none) 
> 
> spmatrix save S3 using S3.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** S4
> spmatrix fromdata S4 = s4_1 - s4_4950, normalize(none) 
> 
> spmatrix save S4 using S4.stswm, replace // inverse: spmatrix use 
> 
> 
> clear 
> 
>         
>                         ***************************
>                         *** Sectors 5-8
>                         *** 120 to 45 
>                         ***************************
>                         
> use spatial_3_wmat_fan_5678
> 
> xtset cell 
> spset cell // must by spset. 
> 
>                 *** S5
> spmatrix fromdata S5 = s5_1 - s5_4950, normalize(none) 
> 
> spmatrix save S5 using S5.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** S6
> spmatrix fromdata S6 = s6_1 - s6_4950, normalize(none) 
> 
> spmatrix save S6 using S6.stswm, replace // inverse: spmatrix use 
> 
>  
>                 *** S7
> spmatrix fromdata S7 = s7_1 - s7_4950, normalize(none) 
> 
> spmatrix save S7 using S7.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** S8
> spmatrix fromdata S8 = s8_1 - s8_4950, normalize(none) 
> 
> spmatrix save S8 using S8.stswm, replace // inverse: spmatrix use 
> 
> 
> clear   
> 
> */
. 
.         ** S1 and 2: sw quadrant 
. spmatrix use S1 using S1.stswm, replace 
{res}{txt}
{com}. spmatrix use S2 using S2.stswm, replace 
{res}{txt}
{com}. 
.         ** S3 to S6: nw quadrant 
. spmatrix use S3 using S3.stswm, replace 
{res}{txt}
{com}. spmatrix use S4 using S4.stswm, replace 
{res}{txt}
{com}. 
. spmatrix use S5 using S5.stswm, replace 
{res}{txt}
{com}. spmatrix use S6 using S6.stswm, replace 
{res}{txt}
{com}. 
.         ** S7 and 8: no quadrant 
. spmatrix use S7 using S7.stswm, replace 
{res}{txt}
{com}. spmatrix use S8 using S8.stswm, replace  
{res}{txt}
{com}.  
. 
. clear 
{txt}
{com}.  
.  
.         ****************************************
.         *** Intersection (4 corners of cell) ***
.         ****************************************
. 
.         
. cd "R:\WSV2\TBu_AKe\Spatial_NEW\Wmat_4corners_reduced"
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Wmat_4corners_reduced
{txt}
{com}. 
.                         
. ***************************
. *** Sectors 1-4 ***********
. *** smaller j *************
. ***************************
. /* 
> use spatial_3_wmat_4corners_1234 
> 
> xtset cell 
> spset cell // must by spset. 
> 
>                 *** S1
> spmatrix fromdata C1 = s1_1 - s1_4950, normalize(none) 
> 
> spmatrix save C1 using C1.stswm, replace // inverse: spmatrix use 
> 
>                 *** C2
> spmatrix fromdata C2 = s2_1 - s2_4950, normalize(none) 
> 
> spmatrix save C2 using C2.stswm, replace // inverse: spmatrix use 
> 
>  
>                 *** C3
> spmatrix fromdata C3 = s3_1 - s3_4950, normalize(none) 
> 
> spmatrix save C3 using C3.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** C4
> spmatrix fromdata C4 = s4_1 - s4_4950, normalize(none) 
> 
> spmatrix save C4 using C4.stswm, replace // inverse: spmatrix use 
> 
> 
> clear 
> 
>         
>                         ***************************
>                         *** Sectors 5-8
>                         *** 120 to 45 
>                         ***************************
>                         
> use spatial_3_wmat_4corners_5678
> 
> xtset cell 
> spset cell // must by spset. 
> 
>                 *** C5
> spmatrix fromdata C5 = s5_1 - s5_4950, normalize(none) 
> 
> spmatrix save C5 using C5.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** C6
> spmatrix fromdata C6 = s6_1 - s6_4950, normalize(none) 
> 
> spmatrix save C6 using C6.stswm, replace // inverse: spmatrix use 
> 
>  
>                 *** C7
> spmatrix fromdata C7 = s7_1 - s7_4950, normalize(none) 
> 
> spmatrix save C7 using C7.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** C8
> spmatrix fromdata C8 = s8_1 - s8_4950, normalize(none) 
> 
> spmatrix save C8 using C8.stswm, replace // inverse: spmatrix use 
> 
> 
> clear   
> 
> */
. 
.         ** C1 and 2: sw quadrant 
. spmatrix use C1 using C1.stswm, replace 
{res}{txt}
{com}. spmatrix use C2 using C2.stswm, replace 
{res}{txt}
{com}. 
.         ** C3 to C6: nw quadrant 
. spmatrix use C3 using C3.stswm, replace 
{res}{txt}
{com}. spmatrix use C4 using C4.stswm, replace 
{res}{txt}
{com}. 
. spmatrix use C5 using C5.stswm, replace 
{res}{txt}
{com}. spmatrix use C6 using C6.stswm, replace 
{res}{txt}
{com}. 
.         ** C7 and 8: no quadrant 
. spmatrix use C7 using C7.stswm, replace 
{res}{txt}
{com}. spmatrix use C8 using C8.stswm, replace 
{res}{txt}
{com}. 
. clear 
{txt}
{com}. 
.                 *******************************
.                 ***    Strips (beam B)          ***
.                 *******************************
.                         
. 
. cd "R:\WSV2\TBu_AKe\Spatial_NEW\Wmat_Beam"
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Wmat_Beam
{txt}
{com}. 
.                 
. /*                      
> ***************************
> *** Sectors 1-4 ***********
> *** smaller j *************
> ***************************
> 
> use spatial_3_wmat_beam_1234 
> 
> xtset cell 
> spset cell // must by spset. 
> 
>                 *** B1
> spmatrix fromdata B1 = s1_1 - s1_4950, normalize(none) 
> 
> spmatrix save B1 using B1.stswm, replace // inverse: spmatrix use 
> 
>                 *** B2
> spmatrix fromdata B2 = s2_1 - s2_4950, normalize(none) 
> 
> spmatrix save B2 using B2.stswm, replace // inverse: spmatrix use 
> 
>  
>                 *** B3
> spmatrix fromdata B3 = s3_1 - s3_4950, normalize(none) 
> 
> spmatrix save B3 using B3.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** B4
> spmatrix fromdata B4 = s4_1 - s4_4950, normalize(none) 
> 
> spmatrix save B4 using B4.stswm, replace // inverse: spmatrix use 
> 
> 
> clear 
> 
>                         ***************************
>                         *** Sectors 5-8  
>                         *** 120 to 45 
>                         ***************************
>                         
> use spatial_3_wmat_beam_5678
> 
> xtset cell 
> spset cell // must by spset. 
> 
>                 *** B5
> spmatrix fromdata B5 = s5_1 - s5_4950, normalize(none) 
> 
> spmatrix save B5 using B5.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** B6
> spmatrix fromdata B6 = s6_1 - s6_4950, normalize(none) 
> 
> spmatrix save B6 using B6.stswm, replace // inverse: spmatrix use 
> 
>  
>                 *** B7
> spmatrix fromdata B7 = s7_1 - s7_4950, normalize(none) 
> 
> spmatrix save B7 using B7.stswm, replace // inverse: spmatrix use 
> 
> 
>                 *** B8
> spmatrix fromdata B8 = s8_1 - s8_4950, normalize(none) 
> 
> spmatrix save B8 using B8.stswm, replace // inverse: spmatrix use 
> 
> 
> clear   
> 
> */ 
. 
.         ** B1 and 2: sw quadrant 
. spmatrix use B1 using B1.stswm, replace 
{res}{txt}
{com}. spmatrix use B2 using B2.stswm, replace 
{res}{txt}
{com}. 
.         ** B3 to B6: nw quadrant 
. spmatrix use B3 using B3.stswm, replace 
{res}{txt}
{com}. spmatrix use B4 using B4.stswm, replace 
{res}{txt}
{com}. 
. spmatrix use B5 using B5.stswm, replace 
{res}{txt}
{com}. spmatrix use B6 using B6.stswm, replace 
{res}{txt}
{com}. 
.         ** B7 and 8: no quadrant 
. spmatrix use B7 using B7.stswm, replace 
{res}{txt}
{com}. spmatrix use B8 using B8.stswm, replace 
{res}{txt}
{com}. 
. clear
{txt}
{com}. 
.  
. 
. *********************************************
. * Transform weight matrix to Finished Data **
. *********************************************
. 
. cd "C:\Users\hy65byfe\Desktop\smerge_0712"
{res}C:\Users\hy65byfe\Desktop\smerge_0712
{txt}
{com}. use spatial_6_regs_s_monthly, replace
{txt}
{com}. 
. drop if missing(date) // from collapse structure 
{txt}(485,100 observations deleted)

{com}. 
. *** spset 
. xtset cell kt // kt: cntry-year observation: must be balanced 
{res}
{col 1}{txt:Panel variable: }{res:cell}{txt: (strongly balanced)}
{p 1 16 2}{txt:Time variable: }{res:kt}{txt:, }{res:{bind:1}}{txt: to }{res:{bind:1176}}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}. capture spset cell  // set identifier
{txt}
{com}. 
. 
. ******** Outcome: sales 
.                 
. replace L3_sd = 0 if missing(L3_sd) // set missing to zero in pre-ban sales 
{txt}(178,200 real changes made)

{com}. replace L3_lsd = 0 if missing(L3_lsd)  // 
{txt}(5,755,246 real changes made)

{com}. 
.                 ** contemp. 
. replace log_sd = 0 if missing(log_sd) // 
{txt}(5,753,524 real changes made)

{com}. 
. ******** Outcome: count 
. 
. replace L3_cd = 0 if missing(L3_cd) // 
{txt}(178,200 real changes made)

{com}. replace L3_lcd = 0 if missing(L3_lcd)  //  
{txt}(5,732,475 real changes made)

{com}.                 
.                 ** contemp. 
. replace log_cd = 0 if missing(log_cd)
{txt}(5,729,921 real changes made)

{com}. 
. 
. ******** Load Matrices
.                         
. spmatrix dir // display active matrices. 
{res}{txt}
{hline 72}
{txt}{col 4}Weighting matrix name{txt}{col 35} N x N{txt}{col 47}Type{txt}{col 60}Normalization
{txt}{hline 72}
{res}{space 22}B1{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}B2{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}B3{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}B4{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}B5{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}B6{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}B7{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}B8{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C1{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C2{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C3{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C4{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C5{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C6{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C7{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}C8{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S1{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S2{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S3{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S4{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S5{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S6{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S7{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{res}{space 22}S8{res}{space 5}4950 x 4950{res}{col 45}custom{res}{col 62}none
{txt}{hline 72}

{com}. 
. ******** Gen Lags 
. 
.  forvalues i = 1/8 {c -(}
{txt}  2{com}.         gen S`i'_L3_sd = 0 
{txt}  3{com}.         gen S`i'_L3_cd = 0 
{txt}  4{com}.         
.         gen C`i'_L3_sd = 0 
{txt}  5{com}.         gen C`i'_L3_cd = 0 
{txt}  6{com}.         
.         gen B`i'_L3_sd = 0 
{txt}  7{com}.         gen B`i'_L3_cd = 0 
{txt}  8{com}. {c )-}
{txt}
{com}.  
. 
. keep if year == 2014 // reduce data in memory to neccessary.  
{txt}(5,405,400 observations deleted)

{com}. 
. egen k14 = group(ccode date) // country-date groups     
{res}{txt}
{com}. 
. drop if missing(date) // 
{txt}(0 observations deleted)

{com}.         
. sum k14, meanonly  // date ccode group. 
{txt}
{com}. scalar kmin = `r(min)' // store in scalars 
{txt}
{com}. scalar kmax = `r(max)'
{txt}
{com}.         
. scalar list kmin kmax // 1 to 84 
{txt}      kmin = {res}         1
{txt}      kmax = {res}        84
{txt}
{com}.  
.  *** spset to verify structure 
. xtset cell k14 // kt: cntry-year observation: must be balanced.
{res}
{col 1}{txt:Panel variable: }{res:cell}{txt: (strongly balanced)}
{p 1 16 2}{txt:Time variable: }{res:k14}{txt:, }{res:{bind:1}}{txt: to }{res:{bind:84}}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}. spset, clear 
{txt}
{com}. spset cell  // set identifier
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_6_regs_s_monthly.dta}
Linked shapefile: <none>
{ralign 16:Data}: Panel
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Time ID}: {res:k14} (see {res:xtset})
{ralign 16:Coordinates}: <none>

{com}. 
. 
.  ******  Create spatial variables for 1 - 8 
.  
. foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.                 
.       spgenerate Waux_`var'_`i' = S1*`var' if k14==`k'
{txt}  5{com}.          quietly replace S1_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C1*`var' if k14==`k'
{txt}  8{com}.          quietly replace C1_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B1*`var' if k14==`k'
{txt} 11{com}.          quietly replace B1_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-} 
{res}{txt}
{com}.  
.  
.  foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.                 
.       spgenerate Waux_`var'_`i' = S2*`var' if k14==`k'
{txt}  5{com}.          quietly replace S2_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C2*`var' if k14==`k'
{txt}  8{com}.          quietly replace C2_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B2*`var' if k14==`k'
{txt} 11{com}.          quietly replace B2_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-} 
{res}{txt}
{com}.  
.  
.   foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.       spgenerate Waux_`var'_`i' = S3*`var' if k14==`k'
{txt}  5{com}.          quietly replace S3_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C3*`var' if k14==`k'
{txt}  8{com}.          quietly replace C3_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B3*`var' if k14==`k'
{txt} 11{com}.          quietly replace B3_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-} 
{res}{txt}
{com}.  
.  
.  
.   foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.                 
.       spgenerate Waux_`var'_`i' = S4*`var' if k14==`k'
{txt}  5{com}.          quietly replace S4_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C4*`var' if k14==`k'
{txt}  8{com}.          quietly replace C4_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B4*`var' if k14==`k'
{txt} 11{com}.          quietly replace B4_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-} 
{res}{txt}
{com}.  
.  
.  foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.                 
.       spgenerate Waux_`var'_`i' = S5*`var' if k14==`k'
{txt}  5{com}.          quietly replace S5_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C5*`var' if k14==`k'
{txt}  8{com}.          quietly replace C5_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B5*`var' if k14==`k'
{txt} 11{com}.          quietly replace B5_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-} 
{res}{txt}
{com}.  
.  
.  foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.                 
.       spgenerate Waux_`var'_`i' = S6*`var' if k14==`k'
{txt}  5{com}.          quietly replace S6_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C6*`var' if k14==`k'
{txt}  8{com}.          quietly replace C6_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B6*`var' if k14==`k'
{txt} 11{com}.          quietly replace B6_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-} 
{res}{txt}
{com}. 
.  
.  
. foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.                 
.       spgenerate Waux_`var'_`i' = S7*`var' if k14==`k'
{txt}  5{com}.          quietly replace S7_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C7*`var' if k14==`k'
{txt}  8{com}.          quietly replace C7_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B7*`var' if k14==`k'
{txt} 11{com}.          quietly replace B7_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-}  
{res}{txt}
{com}.  
.  
.  
. foreach var of varlist L3_sd L3_cd {c -(}
{txt}  2{com}.         forvalues i = `=kmin'/`=kmax' {c -(}
{txt}  3{com}.         local k = `i' 
{txt}  4{com}.                 
.       spgenerate Waux_`var'_`i' = S8*`var' if k14==`k'
{txt}  5{com}.          quietly replace S8_`var'=Waux_`var'_`i' if k14==`k'
{txt}  6{com}.                  drop Waux* 
{txt}  7{com}.                  
.            spgenerate Waux_`var'_`i' = C8*`var' if k14==`k'
{txt}  8{com}.          quietly replace C8_`var'=Waux_`var'_`i' if k14==`k'
{txt}  9{com}.                  drop Waux* 
{txt} 10{com}.                  
.                 spgenerate Waux_`var'_`i' = B8*`var' if k14==`k'
{txt} 11{com}.          quietly replace B8_`var'=Waux_`var'_`i' if k14==`k'
{txt} 12{com}.                  drop Waux* 
{txt} 13{com}.          {c )-} 
{txt} 14{com}.  {c )-}  
{res}{txt}
{com}.  
.  
. *browse cell year ccode S* C* B* L3_sd L3_cd if cell <= 50 & year == 2014 // 
. cd "$store"
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Data
{txt}
{com}. save spatial_regs_s_monthly, replace
{txt}{p 0 4 2}
(file {bf}
spatial_regs_s_monthly.dta{rm}
not found)
{p_end}
{p 0 4 2}
file {bf}
spatial_regs_s_monthly.dta{rm}
saved
{p_end}

{com}. 
{txt}end of do-file

{com}. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}R:\WSV2\TBu_AKe\Spatial_NEW\spatial_4_spgen.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}28 Mar 2023, 18:08:32
{txt}{.-}
{smcl}
{txt}{sf}{ul off}